<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "student".
 *
 * @property int $ID ID
 * @property int $XXID 学校ID
 * @property int|null $BJID 班级ID
 * @property int $GRID 个人ID
 * @property string|null $XH 学号
 * @property string $XSXM 学生姓名
 * @property string $XB 性别
 * @property string $SFZHM 身份证号码
 * @property string $RXSJ 入学时间
 * @property string|null $LXSJ 离校时间
 * @property float|null $BXXF 必修学分
 * @property float|null $XXXF 选修学分
 * @property int|null $BYND 毕业年度
 * @property string|null $BYZBH 毕业证编号
 * @property string|null $BYZ 毕业证
 * @property string|null $FZRQ 发证日期
 * @property string $ZT 状态
 *
 * @property Elective[] $electives
 * @property GraduationEligibleStudent[] $graduationEligibleStudents
 * @property GraduationEligibleAudit[] $bYZGSHes
 * @property Clazz $bJ
 * @property School $xX
 * @property Person $gR
 * @property StudentStatus[] $studentStatuses
 */
class Student extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'student';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['XXID', 'GRID', 'XSXM', 'XB', 'SFZHM', 'RXSJ', 'ZT'], 'required'],
            [['XXID', 'BJID', 'GRID', 'BYND'], 'integer'],
            [['XB'], 'string'],
            [['RXSJ', 'LXSJ', 'FZRQ'], 'safe'],
            [['BXXF', 'XXXF'], 'number'],
            [['XH', 'SFZHM', 'BYZBH'], 'string', 'max' => 20],
            [['XSXM'], 'string', 'max' => 50],
            [['BYZ'], 'string', 'max' => 100],
            [['ZT'], 'string', 'max' => 10],
            [['BJID'], 'exist', 'skipOnError' => true, 'targetClass' => Clazz::className(), 'targetAttribute' => ['BJID' => 'ID']],
            [['XXID'], 'exist', 'skipOnError' => true, 'targetClass' => School::className(), 'targetAttribute' => ['XXID' => 'ID']],
            [['GRID'], 'exist', 'skipOnError' => true, 'targetClass' => Person::className(), 'targetAttribute' => ['GRID' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'XXID' => '学校ID',
            'BJID' => '班级ID',
            'GRID' => '个人ID',
            'XH' => '学号',
            'XSXM' => '学生姓名',
            'XB' => '性别',
            'SFZHM' => '身份证号码',
            'RXSJ' => '入学时间',
            'LXSJ' => '离校时间',
            'BXXF' => '必修学分',
            'XXXF' => '选修学分',
            'BYND' => '毕业年度',
            'BYZBH' => '毕业证编号',
            'BYZ' => '毕业证',
            'FZRQ' => '发证日期',
            'ZT' => '状态',
        ];
    }

    /**
     * Gets query for [[Electives]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getElectives()
    {
        return $this->hasMany(Elective::className(), ['XSID' => 'ID'])->inverseOf('xS');
    }

    /**
     * Gets query for [[GraduationEligibleStudents]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getGraduationEligibleStudents()
    {
        return $this->hasMany(GraduationEligibleStudent::className(), ['XSID' => 'ID'])->inverseOf('xS');
    }

    /**
     * Gets query for [[BYZGSHes]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getBYZGSHes()
    {
        return $this->hasMany(GraduationEligibleAudit::className(), ['ID' => 'BYZGSHID'])->viaTable('graduation_eligible_student', ['XSID' => 'ID']);
    }

    /**
     * Gets query for [[BJ]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getBJ()
    {
        return $this->hasOne(Clazz::className(), ['ID' => 'BJID'])->inverseOf('students');
    }

    /**
     * Gets query for [[XX]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getXX()
    {
        return $this->hasOne(School::className(), ['ID' => 'XXID'])->inverseOf('students');
    }

    /**
     * Gets query for [[GR]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getGR()
    {
        return $this->hasOne(Person::className(), ['id' => 'GRID'])->inverseOf('students');
    }

    /**
     * Gets query for [[StudentStatuses]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getStudentStatuses()
    {
        return $this->hasMany(StudentStatus::className(), ['XSID' => 'ID'])->inverseOf('xS');
    }
}
